function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import setConfig, { casConfig } from './config';
import check, { checkTicket, checkCookieTicket, checkUrlTicket } from './check';
import setCookie, { cookie } from '@yjtec/cas-cookie';
import authorized from './Authorized/';
import event from './events';
import CasContext from './CasContext';
import defaultConfig from './config/config.js';
import redirect from './redirect';
import { setParams, getParams } from './params.js';
import CasWrapper from './wrapper';
export function initCas(opt) {
  //初始化config
  setConfig(_objectSpread(_objectSpread({}, defaultConfig), opt)); //初始化cookie

  var _casConfig$get = casConfig.get('cookie.path', '/'),
      cookieOpt = _casConfig$get.cookieOpt;

  var type = casConfig.get('type');
  setCookie(casConfig.get('type', 'default'), casConfig.get('cookie.path', '/'), casConfig.get('cookie.domain', null));
}
export function login() {
  var uri = getHost();
  var defaultUri = casConfig.get('type') + '/login';
  uri += '/' + casConfig.get('uri.login', defaultUri) + '?redirect=' + redirect();
  window.location.href = uri;
}
export function logout() {
  var uri = getHost();
  var defaultUri = casConfig.get('type') + '/logout';
  uri += '/' + casConfig.get('uri.logout', defaultUri) + '?redirect=' + redirect();
  event.emit('cas.logout', {
    uri: uri
  });
}
export function soc(platfrom, callback) {
  if (platfrom === 'wx') {
    platfrom = 'wechat';
  }

  var uri = getHost();
  uri += '/soc/' + casConfig.get('type', 'default') + '/' + platfrom;

  if (callback) {
    //singlegetuser只获取第三方用户信息，返回soc，不直接跳转登录
    uri += '?singlegetuser=true&callback=' + callback;
  }

  window.location.href = uri;
}
export function getHost() {
  return casConfig.get('host', '/');
}
export { setConfig, casConfig, check, checkTicket, CasContext, authorized, event, cookie, checkCookieTicket, checkUrlTicket, setParams, getParams, CasWrapper };